﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF.RoutingEvents
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static readonly RoutedEvent SuperRoutedEvent;

        public MainWindow()
        {
            InitializeComponent();
            //EventManager.RegisterRoutedEvent("superRouted", RoutingStrategy.Bubble, GetType(RoutedEventArgs), GetType(MainWindow));

            CommandBinding copyCommand = new CommandBinding(ApplicationCommands.Copy);
            CommandBinding pasteCommand = new CommandBinding(ApplicationCommands.Paste);

            this.CommandBindings.Add(copyCommand);
            this.CommandBindings.Add(pasteCommand);
            copyCommand.Executed += copyCommand_Executed;
            pasteCommand.Executed += pasteCommand_Executed;

            

            this.MouseDown += MainWindow_MouseDown;
            this.MouseEnter += MainWindow_MouseEnter;

            myBorder.MouseEnter += MainWindow_MouseEnter;
            myEllipse.MouseEnter += MainWindow_MouseEnter;
            myPanel.MouseEnter += MainWindow_MouseEnter;
            myRectangle.MouseEnter += MainWindow_MouseEnter;

            myRectangle.MouseDown += MainWindow_MouseDown;
            myPanel.MouseDown += MainWindow_MouseDown;
            myEllipse.MouseDown += MainWindow_MouseDown;
            myBorder.MouseDown += MainWindow_MouseDown;

            for (int i = 0; i < 5; i++)
            {
                Button btn = new Button();
                btn.Content = "Button " + i;
                //btn.Click += btn_Click;

                myPanel.Children.Add(btn);
            }

            myPanel.AddHandler(Button.ClickEvent,new RoutedEventHandler(btn_Click));
        }

        void pasteCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (Clipboard.ContainsText())
                Debug.WriteLine(Clipboard.GetText().ToString());
            Debug.WriteLine(e);
        }

        void copyCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Debug.WriteLine("Copy executed!");
           
        }

        void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;
            btn.Background = Brushes.BlueViolet;
        }

        void MainWindow_MouseEnter(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("Mouse entered to " + sender);
        }

        void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Debug.WriteLine("Mouse downed to " + sender);
        }

        //public event RoutedEventHandler SuperRouted
        //{
        //    add { this.AddHandler(SuperRoutedEvent, value); }
        //    remove { this.AddHandler(SuperRoutedEvent, value); }
        //}

        //private void btn1_TextChanged_1(object sender, TextChangedEventArgs e)
        //{

        //}
    }
}
